#!/usr/bin/env bash

# Set shell options that RVM cannot live without,
# see __rvm_setup and __rvm_teardown for further settings.
if
  [[ -n "${BASH_VERSION:-}" ]]
then
  shopt -s extglob
elif
  [[ -n "${ZSH_VERSION:-}" ]]
then
  setopt extendedglob
  setopt kshglob
  setopt no_glob_subst
elif
  [[ -n "${KSH_VERSION:-}" ]]
then
  true # mksh
else
  printf "%b" "What the heck kind of shell are you running here???\n"
fi

# duplication marker jkdfkdfngjdjkfngjkdfngjkd
if
  (( ${rvm_trace_flag:-0} == 1 ))
then
  if   [[ -n "${BASH_VERSION:-}" ]]
  then export PS4="+ \$(__rvm_date \"+%s.%N\" 2>/dev/null) \${BASH_SOURCE##\${rvm_path:-}} : \${FUNCNAME[0]:+\${FUNCNAME[0]}()}  \${LINENO} > "
  elif [[ -n "${ZSH_VERSION:-}" ]]
  then export PS4="+ %* %F{red}%x:%I %F{green}%N:%i%F{white} %_"
  fi
  set -o xtrace
fi

export __rvm_env_loaded
# set env loaded flag if not yet set
: __rvm_env_loaded:${__rvm_env_loaded:=0}:
# increase load count counter
: __rvm_env_loaded:$(( __rvm_env_loaded+=1 )):

# load only if not yet loaded or first time loading
if [[ -z "${rvm_tmp_path:-}" ]] || (( __rvm_env_loaded == 1 ))
then

  if
    \typeset -f __rvm_cleanse_variables >/dev/null 2>&1
  then
    __rvm_cleanse_variables ||
    if [[ -n "${ZSH_VERSION:-}" ]]
    then rvm_error "ZSH Error, run \`rm -f ~/.zcompdump\` and try again."
    fi
  fi

  # Ensure that /etc/rvmrc and $HOME/.rvmrc values take precedence.
  if (( ${rvm_ignore_rvmrc:=0} == 0 ))
  then
    [[ -n "${rvm_stored_umask:-}" ]] || export rvm_stored_umask=$(umask)

    rvm_rvmrc_files=("/etc/rvmrc" "$HOME/.rvmrc")
    if [[ -n "${rvm_prefix:-}" ]] && ! [[ "$HOME/.rvmrc" -ef "${rvm_prefix}/.rvmrc" ]]
    then rvm_rvmrc_files+=( "${rvm_prefix}/.rvmrc" )
    fi
    for rvmrc in "${rvm_rvmrc_files[@]}"
    do
      if [[ -f "$rvmrc" ]]
      then
        if GREP_OPTIONS="" \command \grep '^\s*rvm .*$' "$rvmrc" >/dev/null 2>&1
        then
          printf "%b" "
Error:
          $rvmrc is for rvm settings only.
          rvm CLI may NOT be called from within $rvmrc.
          Skipping the loading of $rvmrc"
          return 1
        else
          source "$rvmrc"
        fi
      fi
    done
    unset rvm_rvmrc_files
  fi

  # duplication marker jdgkjnfnkjdngjkfnd4fd
  export rvm_path
  if [[ -z "${rvm_path:-}" ]]
  then
    if [[ -n "${BASH_SOURCE:-$_}" && -f "${BASH_SOURCE:-$_}" ]]
    then
      rvm_path="${BASH_SOURCE:-$_}"
      rvm_path="$( \command \cd "${rvm_path%/scripts/initialize}">/dev/null; pwd )"
    elif (( UID == 0 )) && [[ -d "/usr/local/rvm" ]]
    then rvm_path="/usr/local/rvm"
    elif [[ -d "${HOME}/.rvm" ]]
    then rvm_path="${HOME}/.rvm"
    elif [[ -d "/usr/local/rvm" ]]
    then rvm_path="/usr/local/rvm"
    else echo "Can't find rvm install!" 1>&2 ; exit 1
    fi
  fi

  true ${rvm_scripts_path:="$rvm_path/scripts"}

  #
  # Setup RVM Environment variables.  Each RVM internal path is intended to be
  # configurable by the end users for whatever their needs may be.
  # They should be set in /etc/rvmrc and then $HOME/.rvmrc
  #
  # duplication marker kkdfkgnjfndgjkndfjkgnkfjdgn
  [[ -n "${rvm_user_install_flag:-}" ]] ||
  case "$rvm_path" in
    (/usr/local/rvm)         rvm_user_install_flag=0 ;;
    ($HOME/*|/${USER// /_}*) rvm_user_install_flag=1 ;;
    (*)                      rvm_user_install_flag=0 ;;
  esac
  export rvm_user_install_flag

  : \
    rvm_bin_path:${rvm_bin_path:="$rvm_path/bin"} \
    rvm_man_path:${rvm_man_path:="$rvm_path/share/man"} \
    rvm_archives_path:${rvm_archives_path:="$rvm_path/archives"} \
    rvm_docs_path:${rvm_docs_path:="$rvm_path/docs"} \
    rvm_environments_path:${rvm_environments_path:="$rvm_path/environments"} \
    rvm_examples_path:${rvm_examples_path:="$rvm_path/examples"} \
    rvm_gems_path:${rvm_gems_path:="$rvm_path/gems"} \
    rvm_gemsets_path:${rvm_gemsets_path:="$rvm_path/gemsets"} \
    rvm_help_path:${rvm_help_path:="$rvm_path/help"} \
    rvm_docs_path:${rvm_docs_path:="$rvm_path/docs"} \
    rvm_hooks_path:${rvm_hooks_path:="$rvm_path/hooks"} \
    rvm_lib_path:${rvm_lib_path:="$rvm_path/lib"} \
    rvm_log_path:${rvm_log_path:="$rvm_path/log"} \
    rvm_patches_path:${rvm_patches_path:="$rvm_path/patches"} \
    rvm_repos_path:${rvm_repos_path:="$rvm_path/repos"} \
    rvm_rubies_path:${rvm_rubies_path:="$rvm_path/rubies"} \
    rvm_rubygems_path:${rvm_rubygems_path:="$rvm_path/rubygems"} \
    rvm_src_path:${rvm_src_path:="$rvm_path/src"} \
    rvm_tmp_path:${rvm_tmp_path:="$rvm_path/tmp"} \
    rvm_user_path:${rvm_user_path:="$rvm_path/user"} \
    rvm_usr_path:${rvm_usr_path:="$rvm_path/usr"} \
    rvm_wrappers_path:${rvm_wrappers_path:="$rvm_path/wrappers"} \
    rvm_verbose_flag:${rvm_verbose_flag:=0} \
    rvm_debug_flag:${rvm_debug_flag:=0} \
    rvm_gems_cache_path:${rvm_gems_cache_path:=${rvm_gems_path:-"$rvm_path/gems"}/cache}

  export rvm_action rvm_alias_expanded rvm_archive_extension rvm_archives_path rvm_bin_flag rvm_bin_path rvm_debug_flag rvm_default_flag rvm_delete_flag rvm_docs_path rvm_docs_type rvm_dump_environment_flag rvm_environments_path rvm_error_message rvm_examples_path rvm_expanding_aliases rvm_file_name rvm_gemdir_flag rvm_gems_cache_path rvm_gems_path rvm_gemset_name rvm_gemset_separator rvm_gemsets_path rvm_gemstone_package_file rvm_gemstone_url rvm_head_flag rvm_help_path rvm_docs_path rvm_hook rvm_hooks_path rvm_install_on_use_flag rvm_lib_path rvm_llvm_flag rvm_loaded_flag rvm_log_path rvm_niceness rvm_nightly_flag rvm_only_path_flag rvm_parse_break rvm_patch_original_pwd rvm_patches_path rvm_path rvm_pretty_print_flag rvm_proxy rvm_quiet_flag rvm_reload_flag rvm_remove_flag rvm_repos_path rvm_rubies_path rvm_ruby_alias rvm_ruby_args rvm_ruby_binary rvm_ruby_bits rvm_ruby_configure rvm_ruby_file rvm_ruby_gem_home rvm_ruby_gem_path rvm_ruby_global_gems_path rvm_ruby_home rvm_ruby_interpreter rvm_ruby_irbrc rvm_ruby_major_version rvm_ruby_make rvm_ruby_make_install rvm_ruby_minor_version rvm_ruby_mode rvm_ruby_name rvm_ruby_package_file rvm_ruby_package_name rvm_ruby_patch rvm_ruby_patch_level rvm_ruby_release_version rvm_ruby_repo_url rvm_ruby_revision rvm_ruby_selected_flag rvm_ruby_sha rvm_ruby_string rvm_ruby_strings rvm_ruby_tag rvm_ruby_url rvm_ruby_user_tag rvm_ruby_version rvm_script_name rvm_scripts_path rvm_sdk rvm_user_install_flag rvm_silent_flag rvm_src_path rvm_sticky_flag rvm_system_flag rvm_tmp_path rvm_token rvm_trace_flag rvm_use_flag rvm_user_flag rvm_user_path rvm_usr_path rvm_verbose_flag rvm_wrappers_path rvm_ruby_repo_branch rvm_man_path rvm_remote_flag rvm_ruby_repo_tag

fi # if [[ -z "${rvm_tmp_path:-}" ]] || (( __rvm_env_loaded == 1 ))
